home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 4 / QRZ Ham Radio Callsign Database - Volume 4.iso / files / satelite / msat09.tgz / VIEWLOG.C < prev    next >
Text File  |  1994-09-17  |  6KB  |  247 lines

  1. /*
  2.  *   Copyright 1992, 1993, 1994 John Melton (G0ORX/N6LYT)
  3.  *              All Rights Reserved
  4.  *
  5.  *   This program is free software; you can redistribute it and/or modify
  6.  *   it under the terms of the GNU General Public License as published by
  7.  *   the Free Software Foundation; either version 1, or (at your option)
  8.  *   any later version.
  9.  *
  10.  *   This program is distributed in the hope that it will be useful,
  11.  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *   GNU General Public License for more details.
  14.  *
  15.  *   You should have received a copy of the GNU General Public License
  16.  *   along with this program; if not, write to the Free Software
  17.  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  */
  20.  
  21. /*
  22.     viewlog.c
  23.  
  24.     X-Window front end to the log display functions.
  25.  
  26.     John Melton
  27.     G0ORX, N6LYT
  28.  
  29.     4 Charlwoods Close
  30.     Copthorne
  31.     West Sussex
  32.     RH10 3QZ
  33.     England
  34.  
  35.     INTERNET:    g0orx@amsat.org
  36.             n6lyt@amsat.org
  37.             john@images.demon.co.uk
  38.             J.D.Melton@slh0613.icl.wins.co.uk
  39.  
  40.     History:
  41.  
  42.     0.1    Initial version.        G4KLX
  43.     0.2    Added WOD display.        G4KLX
  44. */
  45.  
  46. #include <X11/Intrinsic.h>
  47. #include <X11/StringDefs.h>
  48. #include <X11/Shell.h>
  49. #include <X11/Xaw/Cardinals.h>
  50. #include <X11/Xaw/Form.h>
  51. #include <X11/Xaw/Text.h>
  52. #include <X11/Xaw/AsciiText.h>
  53. #include <X11/Xaw/Label.h>
  54. #include <X11/Xaw/Command.h>
  55. #include <X11/Xaw/Viewport.h>
  56.  
  57. #include <stdio.h>
  58. #include <stdlib.h>
  59. #include <unistd.h>
  60. #include <sys/types.h>
  61. #include <sys/wait.h>
  62. #include <fcntl.h>
  63. #include <dirent.h>
  64. #include <signal.h>
  65.  
  66. #include "xawutils.h"
  67. #include "viewlog.h"
  68.  
  69. Display *dpy;
  70.  
  71. XtAppContext app_context;
  72.  
  73. typedef struct
  74. {
  75.     XFontStruct *bold_font, *button_font, *text_font;
  76. }
  77. Resources;
  78.  
  79. Resources  resources;
  80.  
  81. Widget toplevel, compwindow, quitbutton, datawindow;
  82.  
  83. static XtResource resource_list[] =
  84. {
  85.     {"boldFont", XtCFont, XtRFontStruct, sizeof(XFontStruct *),
  86.         XtOffsetOf(Resources, bold_font), XtRString, XtDefaultFont},
  87.     {"buttonFont", XtCFont, XtRFontStruct, sizeof(XFontStruct *),
  88.         XtOffsetOf(Resources, button_font), XtRString, XtDefaultFont},
  89.     {"textFont", XtCFont, XtRFontStruct, sizeof(XFontStruct *),
  90.         XtOffsetOf(Resources, text_font), XtRString, XtDefaultFont}
  91. };
  92.  
  93. static Arg shell_args[] =
  94. {
  95.     {XtNtitle,        (XtArgVal)NULL}
  96. };
  97.  
  98. static Arg form_args[] =
  99. {
  100.     {XtNdefaultDistance,    (XtArgVal)0}
  101. };
  102.  
  103. static Arg button_args[] =
  104. {
  105.     {XtNcallback,        (XtArgVal)NULL},
  106.     {XtNlabel,        (XtArgVal)NULL},
  107.     {XtNfromHoriz,        (XtArgVal)NULL},
  108.     {XtNfont,        (XtArgVal)NULL},
  109.     {XtNresize,        (XtArgVal)False},
  110.     {XtNvertDistance,    (XtArgVal)6},
  111.     {XtNhorizDistance,    (XtArgVal)8},
  112.     {XtNtop,        XtChainTop},
  113.     {XtNbottom,        XtChainTop},
  114.     {XtNleft,        XtChainLeft},
  115.     {XtNright,        XtChainLeft}
  116. };
  117.  
  118. static Arg window_args[] =
  119. {
  120.     {XtNfromVert,        (XtArgVal)NULL},
  121.     {XtNbackground,        (XtArgVal)NULL},
  122.     {XtNfont,        (XtArgVal)NULL},
  123.     {XtNcursor,        (XtArgVal)NULL},
  124.     {XtNwidth,        (XtArgVal)640},
  125.     {XtNheight,        (XtArgVal)260},
  126.     {XtNvertDistance,    (XtArgVal)6},
  127.     {XtNscrollVertical,    XawtextScrollAlways},
  128.     {XtNscrollHorizontal,    XawtextScrollWhenNeeded},
  129.     {XtNeditType,        XawtextEdit},
  130.     {XtNtype,        XawAsciiString},
  131.     {XtNdisplayNonprinting,    False},
  132.     {XtNdisplayCaret,    False},
  133.     {XtNautoFill,        True}
  134. };
  135.  
  136. void writetext(char *message)
  137. {
  138.     static XawTextPosition pos = 0;
  139.     XawTextBlock tt;
  140.  
  141.     tt.firstPos = 0;
  142.     tt.ptr      = message;
  143.     tt.length   = strlen(message);
  144.     tt.format   = FMT8BIT;
  145.  
  146.     XawTextReplace(datawindow, pos, pos, &tt);
  147.  
  148.     pos += strlen(message);
  149. }
  150.  
  151.  
  152. void QuitCb(Widget w, XtPointer client_data, XtPointer call_data)
  153. {
  154.     XtDestroyApplicationContext(app_context);
  155.  
  156.     exit(0);
  157. }
  158.  
  159. int main(int argc, char **argv)
  160. {
  161.     static XtCallbackRec callback[2];
  162.     FILE *fp;
  163.     char *fileName;
  164.  
  165.     if (argc < 2)
  166.     {
  167.         fprintf(stderr, "usage: viewlog [title] <file-name>\n");
  168.         return(1);
  169.     }
  170.  
  171.     toplevel = XtAppInitialize(&app_context, "Xpb", NULL, 0, &argc, argv,
  172.                 NULL, shell_args, XtNumber(shell_args));
  173.  
  174.     XtVaSetValues(toplevel, XtNtitle, argv[1], NULL);
  175.  
  176.     dpy  = XtDisplay(toplevel);
  177.  
  178.     XtGetApplicationResources(toplevel, &resources,
  179.                 resource_list, XtNumber(resource_list),
  180.                 NULL, ZERO);
  181.  
  182.     compwindow = XtCreateManagedWidget("appForm", formWidgetClass,
  183.                 toplevel, form_args, XtNumber(form_args));
  184.  
  185.     callback[0].callback = QuitCb;
  186.     callback[0].closure  = toplevel;
  187.     button_args[0].value = (XtArgVal)callback;
  188.     button_args[1].value = (XtArgVal)"Quit";
  189.     button_args[3].value = (XtArgVal)resources.button_font;
  190.     quitbutton = XtCreateManagedWidget("quitButton", commandWidgetClass,
  191.                 compwindow, button_args, XtNumber(button_args));
  192.  
  193.     window_args[0].value = (XtArgVal)quitbutton;
  194.     window_args[1].value = (XtArgVal)WhitePixel(dpy, DefaultScreen(dpy));
  195.     window_args[2].value = (XtArgVal)resources.text_font;
  196.     datawindow = XtCreateManagedWidget("viewText", asciiTextWidgetClass,
  197.                 compwindow, window_args, XtNumber(window_args));
  198.  
  199.     createMessagePopup(resources.bold_font, resources.button_font);
  200.  
  201.     if (argc == 2)
  202.         fileName = argv[1];
  203.     else
  204.         fileName = argv[2];
  205.  
  206.     if ((fp = fopen(fileName, "r")) == NULL)
  207.     {
  208.         MessageBox("Cannot open input file");
  209.         return(1);
  210.     }
  211.  
  212.     if (strncasecmp(argv[1], "AL", 2) == 0)
  213.     {
  214.         if (alogdisp(fp) != 0)
  215.             MessageBox("Log file is currupt");
  216.     }
  217.     else if (strncasecmp(argv[1], "BL", 2) == 0)
  218.     {
  219.         if (blogdisp(fp) != 0)
  220.             MessageBox("Log file is currupt");
  221.     }
  222.     else if (strncasecmp(argv[1], "CL", 2) == 0)
  223.     {
  224.         if (clogdisp(fp) != 0)
  225.             MessageBox("Log file is currupt");
  226.     }
  227.     else if (strncasecmp(argv[1], "EL", 2) == 0)
  228.     {
  229.         if (elogdisp(fp) != 0)
  230.             MessageBox("Log file is currupt");
  231.     }
  232.     else if (strncasecmp(argv[1], "WD", 2) == 0)
  233.     {
  234.         if (wdlogdisp(fp) != 0)
  235.             MessageBox("Log file is currupt");
  236.     }
  237.  
  238.     fclose(fp);
  239.  
  240.     XtRealizeWidget(toplevel);
  241.  
  242.     XtAppMainLoop(app_context);
  243.     
  244.     return(0);
  245. }
  246.  
  247.